package gt.edu.usac.viewcontroller.backing.app;

import gt.edu.usac.model.am.AppModuleImpl;
import gt.edu.usac.model.vo.centroViewImpl;
import gt.edu.usac.model.vo.edificioViewImpl;
import gt.edu.usac.model.vo.salonViewImpl;

import javax.faces.component.html.HtmlForm;
import javax.faces.context.FacesContext;
import javax.faces.el.ValueBinding;
import javax.faces.event.ActionEvent;

import oracle.adf.model.BindingContext;
import oracle.adf.model.binding.DCDataControl;

import oracle.jbo.ApplicationModule;


public class AdminSalones {
    private HtmlForm form1;

    public void setForm1(HtmlForm form1) {
        this.form1 = form1;
    }

    public HtmlForm getForm1() {
        return form1;
    }


    public void deleteSalon(ActionEvent actionEvent) {
        FacesContext ctx = FacesContext.getCurrentInstance();
        
        //Creando el binding container 
        ValueBinding vb = ctx.getApplication().createValueBinding("#{data}");
        BindingContext bc = (BindingContext)vb.getValue(ctx);
        
        DCDataControl dc  = bc.findDataControl("AppModuleDataControl");
        ApplicationModule am = (ApplicationModule)dc.getDataProvider();
        AppModuleImpl service    = (AppModuleImpl)am;
        
        //Trabajando las queries
        salonViewImpl salon = service.getsalonView2();
        salon.removeCurrentRow();
        service.getDBTransaction().commit();
    }

    public void deleteEdificio(ActionEvent actionEvent) {
         FacesContext ctx = FacesContext.getCurrentInstance();
         
         //Creando el binding container 
         ValueBinding vb = ctx.getApplication().createValueBinding("#{data}");
         BindingContext bc = (BindingContext)vb.getValue(ctx);
         
         DCDataControl dc  = bc.findDataControl("AppModuleDataControl");
         ApplicationModule am = (ApplicationModule)dc.getDataProvider();
         AppModuleImpl service    = (AppModuleImpl)am;
         
         //Trabajando las queries
         edificioViewImpl edificio = service.getedificioView2();
         //Eliminando todos los salones asociados 
         salonViewImpl salon = service.getsalonView2();
         while(salon.getCurrentRow()!=null){
             salon.removeCurrentRow();
         }
         service.getDBTransaction().commit();
         edificio.removeCurrentRow();
         service.getDBTransaction().commit();
    }

    public void deleteCentro(ActionEvent actionEvent) {
         FacesContext ctx = FacesContext.getCurrentInstance();
         
         //Creando el binding container 
         ValueBinding vb = ctx.getApplication().createValueBinding("#{data}");
         BindingContext bc = (BindingContext)vb.getValue(ctx);
         
         DCDataControl dc  = bc.findDataControl("AppModuleDataControl");
         ApplicationModule am = (ApplicationModule)dc.getDataProvider();
         AppModuleImpl service    = (AppModuleImpl)am;
         
         //Trabajando las queries
         centroViewImpl centro = service.getcentroView1();
         
         //Eliminando todos los edificios y salones asociados 
          edificioViewImpl edificio = service.getedificioView2();
          while(edificio.getCurrentRow()!=null){
             
             salonViewImpl salon = service.getsalonView2();
             while(salon.getCurrentRow()!=null){
                 salon.removeCurrentRow();
             }
             service.getDBTransaction().commit();
             edificio.removeCurrentRow();
             service.getDBTransaction().commit();
         }
         service.getDBTransaction().commit();
         
         centro.removeCurrentRow();
         service.getDBTransaction().commit();
    }
}
